<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>PyQt5仿网页鼠标移动点阵特效 | Xing's Blog</title><meta name="author" content="xing"><meta name="copyright" content="xing"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Orz，前段时间有个zz需求，就是要做一个类似网页上很多个多点连线、鼠标移动跟随的那种炫酷特效，然后花了点时间在网上找了js做的，刚开始打算是嵌入QWebView来显示网页，后来研究了下js的算法代码，遂改用QWidget的paintEvent直接绘制。">
<meta property="og:type" content="article">
<meta property="og:title" content="PyQt5仿网页鼠标移动点阵特效">
<meta property="og:url" content="https://veryxing.github.io/article/f1af6d66.html">
<meta property="og:site_name" content="Xing&#39;s Blog">
<meta property="og:description" content="Orz，前段时间有个zz需求，就是要做一个类似网页上很多个多点连线、鼠标移动跟随的那种炫酷特效，然后花了点时间在网上找了js做的，刚开始打算是嵌入QWebView来显示网页，后来研究了下js的算法代码，遂改用QWidget的paintEvent直接绘制。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-10.png">
<meta property="article:published_time" content="2018-10-29T08:49:10.000Z">
<meta property="article:modified_time" content="2024-11-27T17:17:57.613Z">
<meta property="article:author" content="xing">
<meta property="article:tag" content="PyQt">
<meta property="article:tag" content="动画">
<meta property="article:tag" content="特效">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-10.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://veryxing.github.io/article/f1af6d66.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><script>
    (() => {
      
    const saveToLocal = {
      set: (key, value, ttl) => {
        if (!ttl) return
        const expiry = Date.now() + ttl * 86400000
        localStorage.setItem(key, JSON.stringify({ value, expiry }))
      },
      get: key => {
        const itemStr = localStorage.getItem(key)
        if (!itemStr) return undefined
        const { value, expiry } = JSON.parse(itemStr)
        if (Date.now() > expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return value
      }
    }

    window.btf = {
      saveToLocal,
      getScript: (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        Object.entries(attr).forEach(([key, val]) => script.setAttribute(key, val))
        script.onload = script.onreadystatechange = () => {
          if (!script.readyState || /loaded|complete/.test(script.readyState)) resolve()
        }
        script.onerror = reject
        document.head.appendChild(script)
      }),
      getCSS: (url, id) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onload = link.onreadystatechange = () => {
          if (!link.readyState || /loaded|complete/.test(link.readyState)) resolve()
        }
        link.onerror = reject
        document.head.appendChild(link)
      }),
      addGlobalFn: (key, fn, name = false, parent = window) => {
        if (!true && key.startsWith('pjax')) return
        const globalFn = parent.globalFn || {}
        globalFn[key] = globalFn[key] || {}
        if (name && globalFn[key][name]) return
        globalFn[key][name || Object.keys(globalFn[key]).length] = fn
        parent.globalFn = globalFn
      }
    }
  
      
      const activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      const activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }

      btf.activateDarkMode = activateDarkMode
      btf.activateLightMode = activateLightMode

      const theme = saveToLocal.get('theme')
    
          theme === 'dark' ? activateDarkMode() : theme === 'light' ? activateLightMode() : null
        
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        document.documentElement.classList.toggle('hide-aside', asideStatus === 'hide')
      }
    
      
    const detectApple = () => {
      if (/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)) {
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
  
    })()
  </script><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.json","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"未找到符合您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false,"highlightFullpage":false,"highlightMacStyle":true},
  copy: {
    success: '复制成功',
    error: '复制失败',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'null',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'PyQt5仿网页鼠标移动点阵特效',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-11-28 01:17:57'
}</script><meta name="generator" content="Hexo 7.3.0"><link rel="alternate" href="/atom.xml" title="Xing's Blog" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "/images/2.gif" data-lazy-src="/img/butterfly-icon.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">59</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">55</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/gallery/"><i class="fa-fw fas fa-folder-open"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/shuoshuo/"><i class="fa-fw fas fa-folder-open"></i><span> 说说</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url(https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-10.png);"><nav id="nav"><span id="blog-info"><a class="nav-site-title" href="/"><span class="site-name">Xing's Blog</span></a><a class="nav-page-title" href="/"><span class="site-name">PyQt5仿网页鼠标移动点阵特效</span></a></span><div id="menus"><div id="search-button"><span class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></span></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/gallery/"><i class="fa-fw fas fa-folder-open"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/shuoshuo/"><i class="fa-fw fas fa-folder-open"></i><span> 说说</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><span class="site-page"><i class="fas fa-bars fa-fw"></i></span></div></div></nav><div id="post-info"><h1 class="post-title">PyQt5仿网页鼠标移动点阵特效</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2018-10-29T08:49:10.000Z" title="发表于 2018-10-29 16:49:10">2018-10-29</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-11-27T17:17:57.613Z" title="更新于 2024-11-28 01:17:57">2024-11-28</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E4%BE%8B%E5%AD%90/">例子</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title=""><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">浏览量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p>Orz，前段时间有个zz需求，就是要做一个类似网页上很多个多点连线、鼠标移动跟随的那种炫酷特效，然后花了点时间在网上找了js做的，刚开始打算是嵌入<code>QWebView</code>来显示网页，后来研究了下js的算法代码，遂改用<code>QWidget</code>的<code>paintEvent</code>直接绘制。</p>
<span id="more"></span>

<h2 id="大概思路"><a href="#大概思路" class="headerlink" title="大概思路"></a>大概思路</h2><ol>
<li>先根据窗口大小随机创建一些点</li>
<li>遍历这些点并找到与之相关联的点</li>
<li>在动画过程中绘制圆点和画两点之间的连线</li>
<li>属性动画<code>QPropertyAnimation</code>改变颜色的透明度</li>
</ol>
<h2 id="题外"><a href="#题外" class="headerlink" title="题外"></a>题外</h2><ol>
<li>这里没有仔细去研究js里的算法优化,在浏览器里嗖嗖的就生成了,在py里好慢….</li>
<li>尽量在py里优化了循环操作,也简单的做了个cython加速也才提高了1s ? 1倍?…</li>
<li>不要只是为了好看用这玩意儿,和网页的效果一样,占CPU !!!!!!没有任何意义</li>
<li>如果有更好的优化算法请告知, 3Q</li>
<li>pyd是python3.4生成的,删掉pyd也能运行</li>
</ol>
<h2 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h2><p><a target="_blank" rel="noopener" href="https://github.com/PyQt5/PyQt/blob/master/QPropertyAnimation/RlatticeEffect.py">https://github.com/PyQt5/PyQt/blob/master/QPropertyAnimation/RlatticeEffect.py</a></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/env python</span></span><br><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="keyword">from</span> random <span class="keyword">import</span> random</span><br><span class="line"><span class="keyword">from</span> time <span class="keyword">import</span> time</span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> PyQt5.QtCore <span class="keyword">import</span> QPropertyAnimation, QObject, pyqtProperty, QEasingCurve,\</span><br><span class="line">    Qt, QRectF, pyqtSignal</span><br><span class="line"><span class="keyword">from</span> PyQt5.QtGui <span class="keyword">import</span> QColor, QPainterPath, QPainter</span><br><span class="line"><span class="keyword">from</span> PyQt5.QtWidgets <span class="keyword">import</span> QWidget</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">try</span>:</span><br><span class="line">    <span class="keyword">import</span> pointtool  <span class="comment"># @UnusedImport @UnresolvedImport</span></span><br><span class="line">    getDistance = pointtool.getDistance</span><br><span class="line">    findClose = pointtool.findClose</span><br><span class="line"><span class="keyword">except</span>:</span><br><span class="line">    <span class="keyword">import</span> math</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">getDistance</span>(<span class="params">p1, p2</span>):</span><br><span class="line">        <span class="keyword">return</span> math.<span class="built_in">pow</span>(p1.x - p2.x, <span class="number">2</span>) + math.<span class="built_in">pow</span>(p1.y - p2.y, <span class="number">2</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">findClose</span>(<span class="params">points</span>):</span><br><span class="line">        plen = <span class="built_in">len</span>(points)</span><br><span class="line">        <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(plen):</span><br><span class="line">            closest = [<span class="literal">None</span>, <span class="literal">None</span>, <span class="literal">None</span>, <span class="literal">None</span>, <span class="literal">None</span>]</span><br><span class="line">            p1 = points[i]</span><br><span class="line">            <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(plen):</span><br><span class="line">                p2 = points[j]</span><br><span class="line">                dte1 = getDistance(p1, p2)</span><br><span class="line">                <span class="keyword">if</span> p1 != p2:</span><br><span class="line">                    placed = <span class="literal">False</span></span><br><span class="line">                    <span class="keyword">for</span> k <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">5</span>):</span><br><span class="line">                        <span class="keyword">if</span> <span class="keyword">not</span> placed:</span><br><span class="line">                            <span class="keyword">if</span> <span class="keyword">not</span> closest[k]:</span><br><span class="line">                                closest[k] = p2</span><br><span class="line">                                placed = <span class="literal">True</span></span><br><span class="line">                    <span class="keyword">for</span> k <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">5</span>):</span><br><span class="line">                        <span class="keyword">if</span> <span class="keyword">not</span> placed:</span><br><span class="line">                            <span class="keyword">if</span> dte1 &lt; getDistance(p1, closest[k]):</span><br><span class="line">                                closest[k] = p2</span><br><span class="line">                                placed = <span class="literal">True</span></span><br><span class="line">            p1.closest = closest</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Target</span>:</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self, x, y</span>):</span><br><span class="line">        <span class="variable language_">self</span>.x = x</span><br><span class="line">        <span class="variable language_">self</span>.y = y</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Point</span>(<span class="title class_ inherited__">QObject</span>):</span><br><span class="line"></span><br><span class="line">    valueChanged = pyqtSignal()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self, x, ox, y, oy, *args, **kwargs</span>):</span><br><span class="line">        <span class="built_in">super</span>(Point, <span class="variable language_">self</span>).__init__(*args, **kwargs)</span><br><span class="line">        <span class="variable language_">self</span>.__x = x</span><br><span class="line">        <span class="variable language_">self</span>._x = x</span><br><span class="line">        <span class="variable language_">self</span>.originX = ox</span><br><span class="line">        <span class="variable language_">self</span>._y = y</span><br><span class="line">        <span class="variable language_">self</span>.__y = y</span><br><span class="line">        <span class="variable language_">self</span>.originY = oy</span><br><span class="line">        <span class="comment"># 5个闭合点</span></span><br><span class="line">        <span class="variable language_">self</span>.closest = [<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>]</span><br><span class="line">        <span class="comment"># 圆半径</span></span><br><span class="line">        <span class="variable language_">self</span>.radius = <span class="number">2</span> + random() * <span class="number">2</span></span><br><span class="line">        <span class="comment"># 连线颜色</span></span><br><span class="line">        <span class="variable language_">self</span>.lineColor = QColor(<span class="number">156</span>, <span class="number">217</span>, <span class="number">249</span>)</span><br><span class="line">        <span class="comment"># 圆颜色</span></span><br><span class="line">        <span class="variable language_">self</span>.circleColor = QColor(<span class="number">156</span>, <span class="number">217</span>, <span class="number">249</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">initAnimation</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="comment"># 属性动画</span></span><br><span class="line">        <span class="keyword">if</span> <span class="keyword">not</span> <span class="built_in">hasattr</span>(<span class="variable language_">self</span>, <span class="string">&#x27;xanimation&#x27;</span>):</span><br><span class="line">            <span class="variable language_">self</span>.xanimation = QPropertyAnimation(</span><br><span class="line">                <span class="variable language_">self</span>, <span class="string">b&#x27;x&#x27;</span>, <span class="variable language_">self</span>, valueChanged=<span class="variable language_">self</span>.valueChanged.emit,</span><br><span class="line">                easingCurve=QEasingCurve.InOutSine)</span><br><span class="line">            <span class="variable language_">self</span>.yanimation = QPropertyAnimation(</span><br><span class="line">                <span class="variable language_">self</span>, <span class="string">b&#x27;y&#x27;</span>, <span class="variable language_">self</span>, valueChanged=<span class="variable language_">self</span>.valueChanged.emit,</span><br><span class="line">                easingCurve=QEasingCurve.InOutSine,</span><br><span class="line">                finished=<span class="variable language_">self</span>.updateAnimation)</span><br><span class="line">            <span class="variable language_">self</span>.updateAnimation()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">updateAnimation</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="variable language_">self</span>.xanimation.stop()</span><br><span class="line">        <span class="variable language_">self</span>.yanimation.stop()</span><br><span class="line">        duration = (<span class="number">1</span> + random()) * <span class="number">1000</span></span><br><span class="line">        <span class="variable language_">self</span>.xanimation.setDuration(duration)</span><br><span class="line">        <span class="variable language_">self</span>.yanimation.setDuration(duration)</span><br><span class="line">        <span class="variable language_">self</span>.xanimation.setStartValue(<span class="variable language_">self</span>.__x)</span><br><span class="line">        <span class="variable language_">self</span>.xanimation.setEndValue(<span class="variable language_">self</span>.originX - <span class="number">50</span> + random() * <span class="number">100</span>)</span><br><span class="line">        <span class="variable language_">self</span>.yanimation.setStartValue(<span class="variable language_">self</span>.__y)</span><br><span class="line">        <span class="variable language_">self</span>.yanimation.setEndValue(<span class="variable language_">self</span>.originY - <span class="number">50</span> + random() * <span class="number">100</span>)</span><br><span class="line">        <span class="variable language_">self</span>.xanimation.start()</span><br><span class="line">        <span class="variable language_">self</span>.yanimation.start()</span><br><span class="line"></span><br><span class="line"><span class="meta">    @pyqtProperty(<span class="params"><span class="built_in">float</span></span>)</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">x</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="keyword">return</span> <span class="variable language_">self</span>._x</span><br><span class="line"></span><br><span class="line"><span class="meta">    @x.setter</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">x</span>(<span class="params">self, x</span>):</span><br><span class="line">        <span class="variable language_">self</span>._x = x</span><br><span class="line"></span><br><span class="line"><span class="meta">    @pyqtProperty(<span class="params"><span class="built_in">float</span></span>)</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">y</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="keyword">return</span> <span class="variable language_">self</span>._y</span><br><span class="line"></span><br><span class="line"><span class="meta">    @y.setter</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">y</span>(<span class="params">self, y</span>):</span><br><span class="line">        <span class="variable language_">self</span>._y = y</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Window</span>(<span class="title class_ inherited__">QWidget</span>):</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self, *args, **kwargs</span>):</span><br><span class="line">        <span class="built_in">super</span>(Window, <span class="variable language_">self</span>).__init__(*args, **kwargs)</span><br><span class="line">        <span class="variable language_">self</span>.setMouseTracking(<span class="literal">True</span>)</span><br><span class="line">        <span class="variable language_">self</span>.resize(<span class="number">800</span>, <span class="number">600</span>)</span><br><span class="line">        <span class="variable language_">self</span>.points = []</span><br><span class="line">        <span class="variable language_">self</span>.target = Target(<span class="variable language_">self</span>.width() / <span class="number">2</span>, <span class="variable language_">self</span>.height() / <span class="number">2</span>)</span><br><span class="line">        <span class="variable language_">self</span>.initPoints()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">paintEvent</span>(<span class="params">self, event</span>):</span><br><span class="line">        <span class="built_in">super</span>(Window, <span class="variable language_">self</span>).paintEvent(event)</span><br><span class="line">        painter = QPainter()</span><br><span class="line">        painter.begin(<span class="variable language_">self</span>)</span><br><span class="line">        painter.setRenderHint(QPainter.Antialiasing)</span><br><span class="line">        painter.fillRect(<span class="variable language_">self</span>.rect(), Qt.black)</span><br><span class="line">        <span class="variable language_">self</span>.animate(painter)</span><br><span class="line">        painter.end()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">mouseMoveEvent</span>(<span class="params">self, event</span>):</span><br><span class="line">        <span class="built_in">super</span>(Window, <span class="variable language_">self</span>).mouseMoveEvent(event)</span><br><span class="line">        <span class="comment"># 鼠标移动时更新xy坐标</span></span><br><span class="line">        <span class="variable language_">self</span>.target.x = event.x()</span><br><span class="line">        <span class="variable language_">self</span>.target.y = event.y()</span><br><span class="line">        <span class="variable language_">self</span>.update()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">initPoints</span>(<span class="params">self</span>):</span><br><span class="line">        t = time()</span><br><span class="line">        <span class="variable language_">self</span>.points.clear()</span><br><span class="line">        <span class="comment"># 创建点</span></span><br><span class="line">        stepX = <span class="variable language_">self</span>.width() / <span class="number">20</span></span><br><span class="line">        stepY = <span class="variable language_">self</span>.height() / <span class="number">20</span></span><br><span class="line">        <span class="keyword">for</span> x <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>, <span class="variable language_">self</span>.width(), <span class="built_in">int</span>(stepX)):</span><br><span class="line">            <span class="keyword">for</span> y <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>, <span class="variable language_">self</span>.height(), <span class="built_in">int</span>(stepY)):</span><br><span class="line">                ox = x + random() * stepX</span><br><span class="line">                oy = y + random() * stepY</span><br><span class="line">                point = Point(ox, ox, oy, oy)</span><br><span class="line">                point.valueChanged.connect(<span class="variable language_">self</span>.update)</span><br><span class="line">                <span class="variable language_">self</span>.points.append(point)</span><br><span class="line">        <span class="built_in">print</span>(time() - t)</span><br><span class="line"></span><br><span class="line">        t = time()</span><br><span class="line">        <span class="comment"># 每个点寻找5个闭合点</span></span><br><span class="line">        findClose(<span class="variable language_">self</span>.points)</span><br><span class="line">        <span class="built_in">print</span>(time() - t)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">animate</span>(<span class="params">self, painter</span>):</span><br><span class="line">        <span class="keyword">for</span> p <span class="keyword">in</span> <span class="variable language_">self</span>.points:</span><br><span class="line">            <span class="comment"># 检测点的范围</span></span><br><span class="line">            value = <span class="built_in">abs</span>(getDistance(<span class="variable language_">self</span>.target, p))</span><br><span class="line">            <span class="keyword">if</span> value &lt; <span class="number">4000</span>:</span><br><span class="line">                <span class="comment"># 其实就是修改颜色透明度</span></span><br><span class="line">                p.lineColor.setAlphaF(<span class="number">0.3</span>)</span><br><span class="line">                p.circleColor.setAlphaF(<span class="number">0.6</span>)</span><br><span class="line">            <span class="keyword">elif</span> value &lt; <span class="number">20000</span>:</span><br><span class="line">                p.lineColor.setAlphaF(<span class="number">0.1</span>)</span><br><span class="line">                p.circleColor.setAlphaF(<span class="number">0.3</span>)</span><br><span class="line">            <span class="keyword">elif</span> value &lt; <span class="number">40000</span>:</span><br><span class="line">                p.lineColor.setAlphaF(<span class="number">0.02</span>)</span><br><span class="line">                p.circleColor.setAlphaF(<span class="number">0.1</span>)</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                p.lineColor.setAlphaF(<span class="number">0</span>)</span><br><span class="line">                p.circleColor.setAlphaF(<span class="number">0</span>)</span><br><span class="line"></span><br><span class="line">            <span class="comment"># 画线条</span></span><br><span class="line">            <span class="keyword">if</span> p.lineColor.alpha():</span><br><span class="line">                <span class="keyword">for</span> pc <span class="keyword">in</span> p.closest:</span><br><span class="line">                    <span class="keyword">if</span> <span class="keyword">not</span> pc:</span><br><span class="line">                        <span class="keyword">continue</span></span><br><span class="line">                    path = QPainterPath()</span><br><span class="line">                    path.moveTo(p.x, p.y)</span><br><span class="line">                    path.lineTo(pc.x, pc.y)</span><br><span class="line">                    painter.save()</span><br><span class="line">                    painter.setPen(p.lineColor)</span><br><span class="line">                    painter.drawPath(path)</span><br><span class="line">                    painter.restore()</span><br><span class="line"></span><br><span class="line">            <span class="comment"># 画圆</span></span><br><span class="line">            painter.save()</span><br><span class="line">            painter.setPen(Qt.NoPen)</span><br><span class="line">            painter.setBrush(p.circleColor)</span><br><span class="line">            painter.drawRoundedRect(QRectF(</span><br><span class="line">                p.x - p.radius, p.y - p.radius, <span class="number">2</span> * p.radius, <span class="number">2</span> * p.radius), p.radius, p.radius)</span><br><span class="line">            painter.restore()</span><br><span class="line"></span><br><span class="line">            <span class="comment"># 开启动画</span></span><br><span class="line">            p.initAnimation()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    <span class="keyword">import</span> sys</span><br><span class="line">    <span class="keyword">import</span> cgitb</span><br><span class="line">    sys.excepthook = cgitb.enable(<span class="number">1</span>, <span class="literal">None</span>, <span class="number">5</span>, <span class="string">&#x27;&#x27;</span>)</span><br><span class="line">    <span class="keyword">from</span> PyQt5.QtWidgets <span class="keyword">import</span> QApplication</span><br><span class="line">    app = QApplication(sys.argv)</span><br><span class="line">    w = Window()</span><br><span class="line">    w.show()</span><br><span class="line">    sys.exit(app.exec_())</span><br></pre></td></tr></table></figure>

<h2 id="效果图"><a href="#效果图" class="headerlink" title="效果图"></a>效果图</h2><p><img src= "/images/2.gif" data-lazy-src="/PyQt/QPropertyAnimation/ScreenShot/RlatticeEffect.gif" alt="RlatticeEffect"></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://veryXing.github.io">xing</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://veryxing.github.io/article/f1af6d66.html">https://veryxing.github.io/article/f1af6d66.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来源 <a href="https://veryXing.github.io" target="_blank">Xing's Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/PyQt/">PyQt</a><a class="post-meta__tags" href="/tags/%E5%8A%A8%E7%94%BB/">动画</a><a class="post-meta__tags" href="/tags/%E7%89%B9%E6%95%88/">特效</a></div><div class="post-share"><div class="social-share" data-image="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-10.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><a class="prev-post pull-left" href="/article/a3497f7b.html" title="PyQt5之QSlider滑动条点击定位"><img class="cover" src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-9.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">PyQt5之QSlider滑动条点击定位</div></div></a><a class="next-post pull-right" href="/article/1ed0f370.html" title="QDataWidgetMapper 数据库绑定 QLineEdit控件"><img class="cover" src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-8.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">QDataWidgetMapper 数据库绑定 QLineEdit控件</div></div></a></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><a href="/article/2241662d.html" title="PyQt5窗口跟随其它窗口"><img class="cover" src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-3.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2018-10-23</div><div class="title">PyQt5窗口跟随其它窗口</div></div></a><a href="/article/f305b1cc.html" title="PyQt属性动画(QPropertyAnimation)"><img class="cover" src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-4.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-05-08</div><div class="title">PyQt属性动画(QPropertyAnimation)</div></div></a><a href="/article/5a4e93df.html" title="PyQt5动画边框阴影"><img class="cover" src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-6.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2018-09-25</div><div class="title">PyQt5动画边框阴影</div></div></a><a href="/article/8e0d6c55.html" title="PyQt5窗口翻转动画"><img class="cover" src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-10.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-05-15</div><div class="title">PyQt5窗口翻转动画</div></div></a><a href="/article/919044c2.html" title="PyQt5仿网页图片鼠标移动特效"><img class="cover" src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-4.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2018-10-23</div><div class="title">PyQt5仿网页图片鼠标移动特效</div></div></a><a href="/article/c054e672.html" title="PyQt5之图片轮播"><img class="cover" src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-8.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2018-11-24</div><div class="title">PyQt5之图片轮播</div></div></a></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info is-center"><div class="avatar-img"><img src= "/images/2.gif" data-lazy-src="/img/butterfly-icon.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info-name">xing</div><div class="author-info-description"></div><div class="site-data"><a href="/archives/"><div class="headline">文章</div><div class="length-num">59</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">55</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/veryXing"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%A7%E6%A6%82%E6%80%9D%E8%B7%AF"><span class="toc-number">1.</span> <span class="toc-text">大概思路</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A2%98%E5%A4%96"><span class="toc-number">2.</span> <span class="toc-text">题外</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81"><span class="toc-number">3.</span> <span class="toc-text">代码</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%88%E6%9E%9C%E5%9B%BE"><span class="toc-number">4.</span> <span class="toc-text">效果图</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/article/18647ffa.html" title="pytest-qt 测试模态窗体."><img src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-9.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="pytest-qt 测试模态窗体."/></a><div class="content"><a class="title" href="/article/18647ffa.html" title="pytest-qt 测试模态窗体.">pytest-qt 测试模态窗体.</a><time datetime="2024-11-27T17:01:35.284Z" title="发表于 2024-11-28 01:01:35">2024-11-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/article/5a8a6c8d.html" title="post"><img src= "/images/2.gif" data-lazy-src="http://up.36992.com/pic/e6/c5/51/e6c551e768092c8655292d89a4034a74.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="post"/></a><div class="content"><a class="title" href="/article/5a8a6c8d.html" title="post">post</a><time datetime="2024-10-31T15:27:17.000Z" title="发表于 2024-10-31 23:27:17">2024-10-31</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/article/140ab620.html" title="某网站自动下载音乐mp3和歌词"><img src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-6.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="某网站自动下载音乐mp3和歌词"/></a><div class="content"><a class="title" href="/article/140ab620.html" title="某网站自动下载音乐mp3和歌词">某网站自动下载音乐mp3和歌词</a><time datetime="2024-10-31T12:15:16.000Z" title="发表于 2024-10-31 20:15:16">2024-10-31</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/article/32b656da.html" title="PyQt密码管理系统"><img src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-2.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="PyQt密码管理系统"/></a><div class="content"><a class="title" href="/article/32b656da.html" title="PyQt密码管理系统">PyQt密码管理系统</a><time datetime="2024-10-20T14:36:18.000Z" title="发表于 2024-10-20 22:36:18">2024-10-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/article/a0a0fd82.html" title="PyQt5实现桌面小宠物"><img src= "/images/2.gif" data-lazy-src="https://jsd.012700.xyz/gh/jerryc127/CDN/img/material-9.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="PyQt5实现桌面小宠物"/></a><div class="content"><a class="title" href="/article/a0a0fd82.html" title="PyQt5实现桌面小宠物">PyQt5实现桌面小宠物</a><time datetime="2024-10-20T14:28:05.000Z" title="发表于 2024-10-20 22:28:05">2024-10-20</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2019 - 2024 By xing</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="日间和夜间模式切换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><div class="js-pjax"></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="true" data-click="false"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>(() => {
  const pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]

  window.pjax = new Pjax({
    elements: 'a:not([target="_blank"])',
    selectors: pjaxSelectors,
    cacheBust: false,
    analytics: false,
    scrollRestoration: false
  })

  const triggerPjaxFn = (val) => {
    if (!val) return
    Object.values(val).forEach(fn => fn())
  }

  document.addEventListener('pjax:send', () => {
    // removeEventListener
    btf.removeGlobalFnEvent('pjaxSendOnce')
    btf.removeGlobalFnEvent('themeChange')

    // reset readmode
    const $bodyClassList = document.body.classList
    if ($bodyClassList.contains('read-mode')) $bodyClassList.remove('read-mode')

    triggerPjaxFn(window.globalFn.pjaxSend)
  })

  document.addEventListener('pjax:complete', () => {
    btf.removeGlobalFnEvent('pjaxCompleteOnce')
    document.querySelectorAll('script[data-pjax]').forEach(item => {
      const newScript = document.createElement('script')
      const content = item.text || item.textContent || item.innerHTML || ""
      Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
      newScript.appendChild(document.createTextNode(content))
      item.parentNode.replaceChild(newScript, item)
    })

    triggerPjaxFn(window.globalFn.pjaxComplete)
  })

  document.addEventListener('pjax:error', e => {
    if (e.request.status === 404) {
      pjax.loadUrl('/404.html')
    }
  })
})()</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div></body></html>